package com.llp.declaresystem.controller;

import com.llp.declaresystem.domain.Result;
import com.llp.declaresystem.domain.entity.ProjectCategory;
import com.llp.declaresystem.service.AdminService;
import com.llp.declaresystem.service.ProjectCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author llp
 * {@code @date} 2022年11月26日16:40
 */

@RestController
@RequestMapping("/admin")
@Slf4j
public class ProjectMessageController {
    @Autowired
    ProjectCategoryService projectCategoryService;
    @Autowired
    AdminService adminService;
    //获取项目信息列表
    @RequestMapping(value = "/showAllProjectCategorys",method = RequestMethod.GET)
    public Result showAllProjectCategorys()
    {
        List<ProjectCategory> list = projectCategoryService.list();
        if(list!=null) return new Result(200,"成功获取projectCategory",list);
        else return new Result<>(400,"出错了",null);
    }

    //更新项目分类
    @RequestMapping(value = "/updateProject",method = RequestMethod.POST)
    public Result updateProject( @RequestBody ProjectCategory entity)
    {
        boolean b = projectCategoryService.updateById(entity);
        if(b) return new Result(200,"更新成功",null);
        else return new Result<>(400,"出错了",null);
    }
    //删除项目
    @RequestMapping("/deleteProject")
    public Result deleteProject(@RequestParam("id")String id)
    {
        log.info("categoryid={}",id);
      boolean b= adminService.deleteProjectByCategoryid(Integer.parseInt(id));
        if(b) return new Result(200,"删除成功",null);
        else return new Result<>(400,"出错了",null);
    }
    //添加新类别
    @RequestMapping("/addProjectCategory")
    public Result addProjectCategory(@RequestBody ProjectCategory projectCategory)
    {
        boolean b = projectCategoryService.save(projectCategory);
        if(b) return new Result(200,"添加成功",null);
        else return new Result<>(400,"出错了",null);
    }

}
